package com.syzg.base.aduit.model;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.syzg.base.login.model.LoginObject;
import com.syzg.base.merge.model.Person;
import com.syzg.common.util.PKCreator;
import com.zenithsun.common.util.WebUtil;

@SuppressWarnings("serial")
public class Audit implements java.io.Serializable{
	
	private String id;
	private Date date;
	private String userId;
	private Person person;
	private String operateDescribe;
	private String type;
	private String flag;
	private String clientIp;
	
	public Audit() {
		// TODO Auto-generated constructor stub
	}

	public Audit(String operateDescribe,String type,HttpServletRequest request) {
		// TODO Auto-generated constructor stub
		this.id = PKCreator.getPk();
		this.date = new Date();
		this.operateDescribe = operateDescribe;
		this.type = type;
		this.person = getPerson(request);
		this.clientIp = WebUtil.getIpAddr(request);
	}
	
	public Audit(String operateDescribe,String type,String flag,HttpServletRequest request) {
		// TODO Auto-generated constructor stub
		this.id = PKCreator.getPk();
		this.date = new Date();
		this.operateDescribe = operateDescribe;
		this.type = type;
		this.flag = flag;
		this.person =  getPerson(request);
		this.clientIp = WebUtil.getIpAddr(request);
	}
	
	private Person getPerson(HttpServletRequest request){
		Person person = new Person();
		LoginObject lo = (LoginObject)request.getSession().getAttribute("LOGIN_OBJECT");
		if(lo != null){
			person.setId(lo.getPersonId());
		}
		return person;
	}
	
	public Audit(String operateDescribe,String type,String flag,String userId,String clientIp) {
		// TODO Auto-generated constructor stub
		this.id = PKCreator.getPk();
		this.date = new Date();
		this.operateDescribe = operateDescribe;
		this.type = type;
		this.flag = flag;
		Person person = new Person();person.setId(userId);
		this.person = person;
		this.clientIp = clientIp;
	}
	
	public Audit(Person person,String operateDescribe,String type,String flag,String clientIp) {
		// TODO Auto-generated constructor stub
		this.id = PKCreator.getPk();
		this.date = new Date();
		this.person = person;
		this.operateDescribe = operateDescribe;
		this.type = type;
		this.flag = flag;
		this.clientIp = clientIp;
	}
	public Audit(Person person,String operateDescribe,String type,String clientIp) {
		// TODO Auto-generated constructor stub
		this.id = PKCreator.getPk();
		this.date = new Date();
		this.person = person;
		this.operateDescribe = operateDescribe;
		this.type = type;
		this.clientIp = clientIp;
	}
	public String getClientIp() {
		return clientIp;
	}

	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}

	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Person getPerson() {
		return person;
	}
	public void setPerson(Person person) {
		this.person = person;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getOperateDescribe() {
		return operateDescribe;
	}
	public void setOperateDescribe(String operateDescribe) {
		this.operateDescribe = operateDescribe;
	}
}
